{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=1446
  Verdict: Accepted
}
uses SysUtils, Math;
 
type
    contestant = record
               r,n:longint;
    end;
 
var
   i,n,m,k,j,l,r:longint;
   a,p:array[0..2010] of contestant;
 
procedure sort(l,r:longint);
var
   i,j,x:longint;
   y:contestant;
 
begin
i:=l;
j:=r;
x:=a[(l+r) div 2].r;
repeat
      while a[i].r>x do inc(i);
      while a[j].r<x do dec(j);
      if i<=j then begin
         y:=a[i];
         a[i]:=a[j];
         a[j]:=y;
         inc(i);
         dec(j);
      end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
 
procedure sortP(l,r:longint);
var
   i,j,x:longint;
   y:contestant;
 
begin
i:=l;
j:=r;
x:=a[(l+r) div 2].n;
repeat
      while a[i].n<x do inc(i);
      while a[j].n>x do dec(j);
      if i<=j then begin
         y:=a[i];
         a[i]:=a[j];
         a[j]:=y;
         inc(i);
         dec(j);
      end;
until i>j;
if l<j then sortP(l,j);
if i<r then sortP(i,r);
end;
 
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
read(n);
for i:=1 to n do read(a[i].n,a[i].r);
sort(1,n);
l:=1;
r:=1;
for i:=2 to n do begin
    if a[i].r=a[l].r then inc(r);
    if (a[i].r<>a[l].r) or (i=n) then begin
       sortP(l,r);
       l:=i;
       r:=i;
    end;
end;
for i:=1 to n do writeln(a[i].n,' ',a[i].r);
end.